<!DOCTYPE html>
<head> 
<meta charset="UTF-8">
<title>Web留言本</title>
<style type="text/css">
textarea { width: 100%; }
input[type="text"], input[type="password"] { width: 180px; height: 24px; line-height: 24px; }
input[type="submit"], input[type="button"] { width: 80px; height: 24px; line-height: 24px; border: 1px solid #ff6600; border-radius: 4px; background: #ff6600; outline: none; color: #fff; cursor: pointer; margin-top: 6px; }
/*定义表格样式*/
table { border-collapse: collapse; width: 100%; font-size: 14px; color: #666; border: solid 1px #0047E1; }
/*定义列标题样式*/
table th { background: #0047E1; color: #fff; font-size: 16px; }
/*定义隔行背景色，改善视觉效果*/
table tr:nth-child(odd) { background: #eee; }
table tr:hover { background: #ddd; color: #000; }
</style>

<script type="text/javascript">
function saveStorage(id)
{
    var data = document.getElementById(id).value;
    var time = new Date().getTime();
    localStorage.setItem(time,data);
    alert("数据已保存。");
    loadStorage('msg');
}
function loadStorage(id)
{
    var result = '<table border="1">';
    for(var i = 0;i < localStorage.length;i++)
    {
        var key = localStorage.key(i);
        var value = localStorage.getItem(key);
        var date = new Date();
        date.setTime(key);
        var datestr = date.toGMTString();
        result += '<tr><td>' + value + '</td><td>' + datestr + '</td></tr>';
    }
    result += '</table>';
    var target = document.getElementById(id);
    target.innerHTML = result;
}
function clearStorage()
{
    localStorage.clear();
    alert("全部数据被清除。");
    loadStorage('msg');
}

</script>
</head>
<body>
<h1>Web留言本</h1>
<textarea id="memo" cols="60" rows="10"></textarea><br>
<input type="button" value="追加" onclick="saveStorage('memo');">
<input type="button" value="初始化" onclick="clearStorage('msg');">
<hr>
<p id="msg"></p>
</body>
</html>  